/*
 * MemberID.java
 *
 * Created on November 19, 2008, 5:37 AM
 */

package rrs;
import java.sql.*;
/**
 *
 * @author PAUL MOLENDA
 */
public class MemberID extends javax.swing.JFrame {
       private TransactionManager manager;
    /** Creates new form MemberID */
    public MemberID(TransactionManager managerObject) {
        initComponents();  
        conn = DBInterface.dbConnOpen();
        manager = managerObject;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        lblMember = new javax.swing.JLabel();
        txtEnterMemberID = new javax.swing.JTextField();
        btnCancel = new javax.swing.JButton();
        btnOK = new javax.swing.JButton();
        lblmisc = new javax.swing.JLabel();
        lblOrBlank = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        lblMember.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        lblMember.setText("Enter Member ID");
        lblMember.setName("lblMember"); // NOI18N

        txtEnterMemberID.setName("txtEnterMemberID"); // NOI18N

        btnCancel.setText("Cancel");
        btnCancel.setName("btnCancel"); // NOI18N
        btnCancel.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnCancelMouseClicked(evt);
            }
        });

        btnOK.setText("OK");
        btnOK.setName("btnOK"); // NOI18N
        btnOK.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnOKMouseClicked(evt);
            }
        });

        lblmisc.setName("lblmisc"); // NOI18N

        lblOrBlank.setText("Or Blank if you do not have an ID");
        lblOrBlank.setName("lblOrBlank"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(lblmisc))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(39, 39, 39)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(lblMember, javax.swing.GroupLayout.PREFERRED_SIZE, 172, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(16, 16, 16))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(21, 21, 21)
                                .addComponent(lblOrBlank)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 36, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(btnCancel, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(59, 59, 59)
                                .addComponent(btnOK, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(81, 81, 81)
                        .addComponent(txtEnterMemberID, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(39, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lblMember, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lblOrBlank)
                .addGap(18, 18, 18)
                .addComponent(txtEnterMemberID, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 48, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnCancel, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnOK, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(21, 21, 21)
                .addComponent(lblmisc)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
/*
 The user has clicked the ok button.  WE will pass the 
 memberId that was entered to the Transaction Manager
*/    
private void btnOKMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnOKMouseClicked
  String rtn = "";
  String id = txtEnterMemberID.getText();
  if (!(id.equals("")))
  {
    try
     {
         Statement stmt = conn.createStatement();
         ResultSet set = stmt.executeQuery("SELECT FROM MEMBER WHERE MEMBERID = '" + id + "'");         
         manager.setMemberID(set.getString(1));
         if (btnCancel.isEnabled() == true)
         {          
         btnCancel.setEnabled(false);
         btnOK.setEnabled(false);
         lblmisc.setText("MemberId successfully added to transaction");
         }
         stmt.close();
      } catch (SQLException e) {
          //They entered something wrong
			rtn = e.getMessage();
         txtEnterMemberID.setText("");
         lblmisc.setText("You have entered the wrong MemberID");
      }
  }
  else
  {
      if (btnCancel.isEnabled() == true )
      {
      manager.setMemberID("");
      btnCancel.setEnabled(false);
      btnOK.setEnabled(false);
      lblmisc.setText("MemberId successfully added to transaction");
      }
  }        
}//GEN-LAST:event_btnOKMouseClicked
/*
 * The Window is closing, close the db Connection
*/ 
private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
 conn = DBInterface.dbConnClose();
}//GEN-LAST:event_formWindowClosing
//Member clicked cancel cancel the order.
private void btnCancelMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnCancelMouseClicked
 if (btnCancel.isEnabled() == true )
      {
      manager.setMemberID("");
      btnCancel.setEnabled(false);
      btnOK.setEnabled(false);
      lblmisc.setText("MemberId successfully added to transaction");
      }
}//GEN-LAST:event_btnCancelMouseClicked

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCancel;
    private javax.swing.JButton btnOK;
    private javax.swing.JLabel lblMember;
    private javax.swing.JLabel lblOrBlank;
    private javax.swing.JLabel lblmisc;
    private javax.swing.JTextField txtEnterMemberID;
    // End of variables declaration//GEN-END:variables
    Connection conn;
}
